home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 April / macformat-049.iso / mac / Shareware Plus / Developers / dropg++ / usr / include / sys / vnode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  13.8 KB  |  398 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1989, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)vnode.h    8.7 (Berkeley) 2/4/94
  34.  */
  35.  
  36. #include <sys/queue.h>
  37.  
  38. /*
  39.  * The vnode is the focus of all file activity in UNIX.  There is a
  40.  * unique vnode allocated for each active file, each current directory,
  41.  * each mounted-on file, text file, and the root.
  42.  */
  43.  
  44. /*
  45.  * Vnode types.  VNON means no type.
  46.  */
  47. enum vtype    { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
  48.  
  49. /*
  50.  * Vnode tag types.
  51.  * These are for the benefit of external programs only (e.g., pstat)
  52.  * and should NEVER be inspected by the kernel.
  53.  */
  54. enum vtagtype    {
  55.     VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_PC, VT_LFS, VT_LOFS, VT_FDESC,
  56.     VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
  57.     VT_UNION
  58. };
  59.  
  60. /*
  61.  * Each underlying filesystem allocates its own private area and hangs
  62.  * it from v_data.  If non-null, this area is freed in getnewvnode().
  63.  */
  64. LIST_HEAD(buflists, buf);
  65.  
  66. struct vnode {
  67.     u_long    v_flag;                /* vnode flags (see below) */
  68.     short    v_usecount;            /* reference count of users */
  69.     short    v_writecount;            /* reference count of writers */
  70.     long    v_holdcnt;            /* page & buffer references */
  71.     daddr_t    v_lastr;            /* last read (read-ahead) */
  72.     u_long    v_id;                /* capability identifier */
  73.     struct    mount *v_mount;            /* ptr to vfs we are in */
  74.     int     (**v_op)();            /* vnode operations vector */
  75.     TAILQ_ENTRY(vnode) v_freelist;        /* vnode freelist */
  76.     LIST_ENTRY(vnode) v_mntvnodes;        /* vnodes for mount point */
  77.     struct    buflists v_cleanblkhd;        /* clean blocklist head */
  78.     struct    buflists v_dirtyblkhd;        /* dirty blocklist head */
  79.     long    v_numoutput;            /* num of writes in progress */
  80.     enum    vtype v_type;            /* vnode type */
  81.     union {
  82.         struct mount    *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
  83.         struct socket    *vu_socket;    /* unix ipc (VSOCK) */
  84.         caddr_t        vu_vmdata;    /* private data for vm (VREG) */
  85.         struct specinfo    *vu_specinfo;    /* device (VCHR, VBLK) */
  86.         struct fifoinfo    *vu_fifoinfo;    /* fifo (VFIFO) */
  87.     } v_un;
  88.     struct    nqlease *v_lease;        /* Soft reference to lease */
  89.     daddr_t    v_lastw;            /* last write (write cluster) */
  90.     daddr_t    v_cstart;            /* start block of cluster */
  91.     daddr_t    v_lasta;            /* last allocation */
  92.     int    v_clen;                /* length of current cluster */
  93.     int    v_ralen;            /* Read-ahead length */
  94.     daddr_t    v_maxra;            /* last readahead block */
  95.     long    v_spare[7];            /* round to 128 bytes */
  96.     enum    vtagtype v_tag;            /* type of underlying data */
  97.     void     *v_data;            /* private data for fs */
  98. };
  99. #define    v_mountedhere    v_un.vu_mountedhere
  100. #define    v_socket    v_un.vu_socket
  101. #define    v_vmdata    v_un.vu_vmdata
  102. #define    v_specinfo    v_un.vu_specinfo
  103. #define    v_fifoinfo    v_un.vu_fifoinfo
  104.  
  105. /*
  106.  * Vnode flags.
  107.  */
  108. #define    VROOT        0x0001    /* root of its file system */
  109. #define    VTEXT        0x0002    /* vnode is a pure text prototype */
  110. #define    VSYSTEM        0x0004    /* vnode being used by kernel */
  111. #define    VXLOCK        0x0100    /* vnode is locked to change underlying type */
  112. #define    VXWANT        0x0200    /* process is waiting for vnode */
  113. #define    VBWAIT        0x0400    /* waiting for output to complete */
  114. #define    VALIASED    0x0800    /* vnode has an alias */
  115. #define    VDIROP        0x1000    /* LFS: vnode is involved in a directory op */
  116.  
  117. /*
  118.  * Vnode attributes.  A field value of VNOVAL represents a field whose value
  119.  * is unavailable (getattr) or which is not to be changed (setattr).
  120.  */
  121. struct vattr {
  122.     enum vtype    va_type;    /* vnode type (for create) */
  123.     u_short        va_mode;    /* files access mode and type */
  124.     short        va_nlink;    /* number of references to file */
  125.     uid_t        va_uid;        /* owner user id */
  126.     gid_t        va_gid;        /* owner group id */
  127.     long        va_fsid;    /* file system id (dev for now) */
  128.     long        va_fileid;    /* file id */
  129.     u_quad_t    va_size;    /* file size in bytes */
  130.     long        va_blocksize;    /* blocksize preferred for i/o */
  131.     struct timespec    va_atime;    /* time of last access */
  132.     struct timespec    va_mtime;    /* time of last modification */
  133.     struct timespec    va_ctime;    /* time file changed */
  134.     u_long        va_gen;        /* generation number of file */
  135.     u_long        va_flags;    /* flags defined for file */
  136.     dev_t        va_rdev;    /* device the special file represents */
  137.     u_quad_t    va_bytes;    /* bytes of disk space held by file */
  138.     u_quad_t    va_filerev;    /* file modification number */
  139.     u_int        va_vaflags;    /* operations flags, see below */
  140.     long        va_spare;    /* remain quad aligned */
  141. };
  142.  
  143. /*
  144.  * Flags for va_cflags.
  145.  */
  146. #define    VA_UTIMES_NULL    0x01        /* utimes argument was NULL */
  147.  
  148. /*
  149.  * Flags for ioflag.
  150.  */
  151. #define    IO_UNIT        0x01        /* do I/O as atomic unit */
  152. #define    IO_APPEND    0x02        /* append write to end */
  153. #define    IO_SYNC        0x04        /* do I/O synchronously */
  154. #define    IO_NODELOCKED    0x08        /* underlying node already locked */
  155. #define    IO_NDELAY    0x10        /* FNDELAY flag set in file table */
  156.  
  157. /*
  158.  *  Modes.  Some values same as Ixxx entries from inode.h for now.
  159.  */
  160. #define    VSUID    04000        /* set user id on execution */
  161. #define    VSGID    02000        /* set group id on execution */
  162. #define    VSVTX    01000        /* save swapped text even after use */
  163. #define    VREAD    00400        /* read, write, execute permissions */
  164. #define    VWRITE    00200
  165. #define    VEXEC    00100
  166.  
  167. /*
  168.  * Token indicating no attribute value yet assigned.
  169.  */
  170. #define    VNOVAL    (-1)
  171.  
  172. #ifdef KERNEL
  173. /*
  174.  * Convert between vnode types and inode formats (since POSIX.1
  175.  * defines mode word of stat structure in terms of inode formats).
  176.  */
  177. extern enum vtype    iftovt_tab[];
  178. extern int        vttoif_tab[];
  179. #define IFTOVT(mode)    (iftovt_tab[((mode) & S_IFMT) >> 12])
  180. #define VTTOIF(indx)    (vttoif_tab[(int)(indx)])
  181. #define MAKEIMODE(indx, mode)    (int)(VTTOIF(indx) | (mode))
  182.  
  183. /*
  184.  * Flags to various vnode functions.
  185.  */
  186. #define    SKIPSYSTEM    0x0001        /* vflush: skip vnodes marked VSYSTEM */
  187. #define    FORCECLOSE    0x0002        /* vflush: force file closeure */
  188. #define    WRITECLOSE    0x0004        /* vflush: only close writeable files */
  189. #define    DOCLOSE        0x0008        /* vclean: close active files */
  190. #define    V_SAVE        0x0001        /* vinvalbuf: sync file first */
  191. #define    V_SAVEMETA    0x0002        /* vinvalbuf: leave indirect blocks */
  192.  
  193. #ifdef DIAGNOSTIC
  194. #define    HOLDRELE(vp)    holdrele(vp)
  195. #define    VATTR_NULL(vap)    vattr_null(vap)
  196. #define    VHOLD(vp)    vhold(vp)
  197. #define    VREF(vp)    vref(vp)
  198.  
  199. void    holdrele __P((struct vnode *));
  200. void    vattr_null __P((struct vattr *));
  201. void    vhold __P((struct vnode *));
  202. void    vref __P((struct vnode *));
  203. #else
  204. #define    HOLDRELE(vp)    (vp)->v_holdcnt--    /* decrease buf or page ref */
  205. #define    VATTR_NULL(vap)    (*(vap) = va_null)    /* initialize a vattr */
  206. #define    VHOLD(vp)    (vp)->v_holdcnt++    /* increase buf or page ref */
  207. #define    VREF(vp)    (vp)->v_usecount++    /* increase reference */
  208. #endif
  209.  
  210. #define    NULLVP    ((struct vnode *)NULL)
  211.  
  212. /*
  213.  * Global vnode data.
  214.  */
  215. extern    struct vnode *rootvnode;    /* root (i.e. "/") vnode */
  216. extern    int desiredvnodes;        /* number of vnodes desired */
  217. extern    struct vattr va_null;        /* predefined null vattr structure */
  218.  
  219. /*
  220.  * Macro/function to check for client cache inconsistency w.r.t. leasing.
  221.  */
  222. #define    LEASE_READ    0x1        /* Check lease for readers */
  223. #define    LEASE_WRITE    0x2        /* Check lease for modifiers */
  224.  
  225. #ifdef NFS
  226. void    lease_check __P((struct vnode *vp, struct proc *p,
  227.         struct ucred *ucred, int flag));
  228. void    lease_updatetime __P((int deltat));
  229. #define    LEASE_CHECK(vp, p, cred, flag)    lease_check((vp), (p), (cred), (flag))
  230. #define    LEASE_UPDATETIME(dt)        lease_updatetime(dt)
  231. #else
  232. #define    LEASE_CHECK(vp, p, cred, flag)
  233. #define    LEASE_UPDATETIME(dt)
  234. #endif /* NFS */
  235. #endif /* KERNEL */
  236.  
  237.  
  238. /*
  239.  * Mods for exensibility.
  240.  */
  241.  
  242. /*
  243.  * Flags for vdesc_flags:
  244.  */
  245. #define VDESC_MAX_VPS        16
  246. /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
  247. #define VDESC_VP0_WILLRELE    0x0001
  248. #define VDESC_VP1_WILLRELE    0x0002
  249. #define VDESC_VP2_WILLRELE    0x0004
  250. #define VDESC_VP3_WILLRELE    0x0008
  251. #define VDESC_NOMAP_VPP        0x0100
  252. #define VDESC_VPP_WILLRELE    0x0200
  253.  
  254. /*
  255.  * VDESC_NO_OFFSET is used to identify the end of the offset list
  256.  * and in places where no such field exists.
  257.  */
  258. #define VDESC_NO_OFFSET -1
  259.  
  260. /*
  261.  * This structure describes the vnode operation taking place.
  262.  */
  263. struct vnodeop_desc {
  264.     int    vdesc_offset;        /* offset in vector--first for speed */
  265.     char    *vdesc_name;        /* a readable name for debugging */
  266.     int    vdesc_flags;        /* VDESC_* flags */
  267.  
  268.     /*
  269.      * These ops are used by bypass routines to map and locate arguments.
  270.      * Creds and procs are not needed in bypass routines, but sometimes
  271.      * they are useful to (for example) transport layers.
  272.      * Nameidata is useful because it has a cred in it.
  273.      */
  274.     int    *vdesc_vp_offsets;    /* list ended by VDESC_NO_OFFSET */
  275.     int    vdesc_vpp_offset;    /* return vpp location */
  276.     int    vdesc_cred_offset;    /* cred location, if any */
  277.     int    vdesc_proc_offset;    /* proc location, if any */
  278.     int    vdesc_componentname_offset; /* if any */
  279.     /*
  280.      * Finally, we've got a list of private data (about each operation)
  281.      * for each transport layer.  (Support to manage this list is not
  282.      * yet part of BSD.)
  283.      */
  284.     caddr_t    *vdesc_transports;
  285. };
  286.  
  287. #ifdef KERNEL
  288. /*
  289.  * A list of all the operation descs.
  290.  */
  291. extern struct vnodeop_desc *vnodeop_descs[];
  292.  
  293.  
  294. /*
  295.  * This macro is very helpful in defining those offsets in the vdesc struct.
  296.  *
  297.  * This is stolen from X11R4.  I ingored all the fancy stuff for
  298.  * Crays, so if you decide to port this to such a serious machine,
  299.  * you might want to consult Intrisics.h's XtOffset{,Of,To}.
  300.  */
  301. #define VOPARG_OFFSET(p_type,field) \
  302.         ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
  303. #define VOPARG_OFFSETOF(s_type,field) \
  304.     VOPARG_OFFSET(s_type*,field)
  305. #define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \
  306.     ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET)))
  307.  
  308.  
  309. /*
  310.  * This structure is used to configure the new vnodeops vector.
  311.  */
  312. struct vnodeopv_entry_desc {
  313.     struct vnodeop_desc *opve_op;   /* which operation this is */
  314.     int (*opve_impl)();        /* code implementing this operation */
  315. };
  316. struct vnodeopv_desc {
  317.             /* ptr to the ptr to the vector where op should go */
  318.     int (***opv_desc_vector_p)();
  319.     struct vnodeopv_entry_desc *opv_desc_ops;   /* null terminated list */
  320. };
  321.  
  322. /*
  323.  * A default routine which just returns an error.
  324.  */
  325. int vn_default_error __P((void));
  326.  
  327. /*
  328.  * A generic structure.
  329.  * This can be used by bypass routines to identify generic arguments.
  330.  */
  331. struct vop_generic_args {
  332.     struct vnodeop_desc *a_desc;
  333.     /* other random data follows, presumably */
  334. };
  335.  
  336. /*
  337.  * VOCALL calls an op given an ops vector.  We break it out because BSD's
  338.  * vclean changes the ops vector and then wants to call ops with the old
  339.  * vector.
  340.  */
  341. #define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
  342.  
  343. /*
  344.  * This call works for vnodes in the kernel.
  345.  */
  346. #define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
  347. #define VDESC(OP) (& __CONCAT(OP,_desc))
  348. #define VOFFSET(OP) (VDESC(OP)->vdesc_offset)
  349.  
  350. /*
  351.  * Finally, include the default set of vnode operations.
  352.  */
  353. #include <vnode_if.h>
  354.  
  355. /*
  356.  * Public vnode manipulation functions.
  357.  */
  358. struct file;
  359. struct mount;
  360. struct nameidata;
  361. struct proc;
  362. struct stat;
  363. struct ucred;
  364. struct uio;
  365. struct vattr;
  366. struct vnode;
  367. struct vop_bwrite_args;
  368.  
  369. int     bdevvp __P((dev_t dev, struct vnode **vpp));
  370. int     getnewvnode __P((enum vtagtype tag,
  371.         struct mount *mp, int (**vops)(), struct vnode **vpp));
  372. int    vinvalbuf __P((struct vnode *vp, int save, struct ucred *cred,
  373.         struct proc *p, int slpflag, int slptimeo));
  374. void     vattr_null __P((struct vattr *vap));
  375. int     vcount __P((struct vnode *vp));
  376. int     vget __P((struct vnode *vp, int lockflag));
  377. void     vgone __P((struct vnode *vp));
  378. void     vgoneall __P((struct vnode *vp));
  379. int    vn_bwrite __P((struct vop_bwrite_args *ap));
  380. int     vn_close __P((struct vnode *vp,
  381.         int flags, struct ucred *cred, struct proc *p));
  382. int     vn_closefile __P((struct file *fp, struct proc *p));
  383. int    vn_ioctl __P((struct file *fp, int com, caddr_t data, struct proc *p));
  384. int     vn_open __P((struct nameidata *ndp, int fmode, int cmode));
  385. int     vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
  386.         int len, off_t offset, enum uio_seg segflg, int ioflg,
  387.         struct ucred *cred, int *aresid, struct proc *p));
  388. int    vn_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
  389. int    vn_select __P((struct file *fp, int which, struct proc *p));
  390. int    vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p));
  391. int    vn_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
  392. struct vnode *
  393.     checkalias __P((struct vnode *vp, dev_t nvp_rdev, struct mount *mp));
  394. void     vput __P((struct vnode *vp));
  395. void     vref __P((struct vnode *vp));
  396. void     vrele __P((struct vnode *vp));
  397. #endif /* KERNEL */
  398.